<?php
//登陆功能
	//获取页面上用户填写的信息
	$name = $_GET['name'];
	$password = $_GET['password'];
	$userimg=$_GET['userimg'];
	//查询头像
	session_start();
	$_SESSION['name']="$name";
	$_SESSION['touxiang_img']="$userimg";
	$sqll="SELECT touxiang_img FROM tbl_user WHERE `name`='$name'";
	//查询数据库
	$sql = "select * from tbl_user where `name` = '$name' ";	
	//比对数据库 是不是有这个人？
	$link = mysqli_connect("127.0.0.1","root","","news");
	mysqli_set_charset($link, "utf8");
	if(mysqli_connect_errno($link)){
		echo "连接失败".mysqli_connect_error($link);
	}
	//执行查询语句
	$res=mysqli_query($link, $sql);
	$ras=mysqli_query($link, $sqll);
	if(mysqli_num_rows($ras)>0){
		while($raw = mysqli_fetch_assoc($ras)){
			   $rasults[]=$raw;
//			echo json_encode($rasults);
		}
			
		
	}

	$arr=array();
	//查询语句得到的记录行数
	if(mysqli_num_rows($res)>0){
		//获取到查询的数据
		while($row = mysqli_fetch_assoc($res)){
			//判断密码是否正确
			if($row['password'] == $password){
				$arr['code'] = 1;
				$arr['message'] = "登陆成功";	
				echo json_encode($arr);
			}else{
				$arr['code'] = -10006;
				$arr['message'] = "密码不正确";	
				echo json_encode($arr);
			}
		}	
	}else{
		$arr['code'] = -10007;
		$arr['message'] = "用户名不存在";	
		echo json_encode($arr);
	}
	//返回结果给用户
	





?>
